﻿/*
* edirauth - http://edirauth.codeplex.com
* A .NET library and utility for authenticating to eDirectory
* Copyright (c) 2013 Matt Shirilla (http://shirilla.com)
* Licensed under the Microsoft Public License (MS-RL)
* http://edirauth.codeplex.com/license
*/

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using edirAuth;
using Novell.Directory.Ldap;

namespace edirAuthTests
{
    [TestClass]
    public class DNlookupTests
    {

        //TODO        //!!!!!!!!!!!!  need to test lookup of a non-existent atr
        EdirAuthorizer eDirAuthorizer;

        [TestInitialize()]
        public void Initialize() {
            eDirAuthorizer = Helper.EdirAuthorizerFactory();
        }

        /// <summary>
        /// Test should lookup the DN by querying for the uid or other attribute.
        /// </summary>
        [TestMethod]
        public void LookupValidUser()         {
            AuthInfo authInfo = new AuthInfo(Helper.TESTUSER01_UID);
            authInfo = eDirAuthorizer.connectAndBind(authInfo);
            authInfo = eDirAuthorizer.dnLookup_onAttr(authInfo);
            Assert.AreEqual(ResultCodes.OK, authInfo.BindResult.Code, "bind:The wrong code was returned.");
            Assert.AreEqual(Helper.TESTUSER01_DN, authInfo.LdapEntry.DN, "dnlookup:The wrong DN was returned.");
            Assert.AreEqual(Helper.TESTUSER01_DN, authInfo.DNLookupResult.Desc, "dnlookup:There was an error or the wrong DN was returned.");
        }

        /// <summary>
        /// Test should fail to lookup the DN by querying for a non-existent uid or other attribute.
        /// </summary>
        [TestMethod]
        public void LookupUser_badAttrValue()        {
            AuthInfo authInfo = new AuthInfo("non-existant attribute value");
            authInfo = eDirAuthorizer.connectAndBind(authInfo);
            authInfo = eDirAuthorizer.dnLookup_onAttr(authInfo);
            Assert.AreNotEqual(ResultCodes.OK, authInfo.DNLookupResult.Code, "The OK was returned for a non-exiustant user.");
            Assert.AreEqual(ResultCodes.NO_RESULTS, authInfo.DNLookupResult.Code, "A user was found for a non-existent attrribute value.");
            Assert.AreEqual(ResultCodes.OK, authInfo.BindResult.Code, "Wrong code was returned");
            Assert.AreEqual(ResultCodes.OK_DESC, authInfo.BindResult.Desc, "Wrong code description was returned.");
        }



    
    
    }//class
}//namespace
